package com.shuyun.springsecurity.showcase.service;

import com.shuyun.springsecurity.showcase.domain.SysUser;
import com.shuyun.springsecurity.showcase.repository.SysUserReporsitory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Created by feng.ding on 2017/1/10.
 */
public class CustomUserService implements UserDetailsService {

    @Autowired
    private SysUserReporsitory userReporsitory;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser user = userReporsitory.findByUsername(username);
        if(user == null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        return user;
    }
}
